import React from 'react';
import './index.less';
import render from 'src/hrpub/common/frame/render';
import {connect} from 'src/hrpub/common/store';
import {COMMON} from "../../../../unit/util";
import Act from "./actions"
import DetailHeader from "../Header"
import DetailTable from "../Table"
import {
    OrgRefer,
    ChangeTypeRefer,
    EmptyRefer, FormBtn,
    PsnclRefer,
    RangeDateRefer
} from "../Refer/refer";
import DetailCommonAction from "../../actions/detailCommon";
import TotaltypeRefer from "../Refer/TotalType";

const initData = {
    org: null, //组织
    psncl: null, //人员类别
    change: true, //变动统计
    entrydimi: false, //入离职统计
    pk_chgtype: "", //变动类型
    pk_dimitype: "", //离职类型
    pk_entrytype: "", //入职类型
    rangeDate: [], //起止日期
}
const DetailWarper = render({
    actions: {
        thisAct: DetailCommonAction,
        cardAct: Act, //人员变动分析 和 入离职趋势 同用一个action
    },
    state: {
        searchVal: null,  // <string> 搜索所属组织/人员类别
        showAdv: false,  //高级按钮
        pageInfo: COMMON.pageInfo,  //分页
        advObj: {...initData},
        initData
    }
})(({props, action, state}) => {
    const {staffCom} = props;
    let language = staffCom.language;
    return (
        <div className={`${staffCom.page}-detail`}>
            <DetailHeader
                {...props}
                pageParam={{titel: COMMON.pageTotal, index: 0}}
                searchVal={state.searchVal}
                searchValChange={action.thisAct.searchValChange}
                searchClick={action.thisAct.search}
                updateState={action.thisAct.updateState}
                clickExport={action.thisAct.clickExport}
            />
            <If condition={state.showAdv}>
                <div className={'pro-search-panel'}>
                    <div className={'form-box'}>
                        <div className={'form-refer'}>
                            <OrgRefer
                                val={state.advObj.org}
                                onChange={(val) => {
                                    action.thisAct.referChange('org', val)
                                }}
                                language={language}
                            />
                            <PsnclRefer
                                val={state.advObj.psncl}
                                onChange={(val) => {
                                    action.thisAct.referChange('psncl', val)
                                }}
                                language={language}
                            />
                            <TotaltypeRefer
                                isFlow={true}
                                val={{entrydimi: state.advObj.entrydimi, change: state.advObj.change}}
                                onChange={(val) => {
                                    action.thisAct.referChange(val)
                                }}
                                language={language}
                            />
                        </div>
                        <div className={'form-refer'}>
                            <RangeDateRefer
                                val={state.advObj.rangeDate}
                                onChange={(val) => {
                                    action.thisAct.referChange('rangeDate', val)
                                }}
                                language={language}
                                param={{format: "YYYY-MM"}}
                            />
                            <ChangeTypeRefer
                                val={state.advObj.pk_chgtype}
                                onChange={(val) => {
                                    action.thisAct.referChange('pk_chgtype', val)
                                }}
                                language={language}
                            />
                            <EmptyRefer/>
                            {/*<DimiTypeRefer*/}
                            {/*val={state.advObj.pk_dimitype}*/}
                            {/*onChange={(val)=>{*/}
                            {/*action.thisAct.referChange('pk_dimitype',val)*/}
                            {/*}}*/}
                            {/*language={language}*/}
                            {/*/>*/}
                        </div>
                    </div>
                    <FormBtn
                        action={action}
                        staffCom={staffCom}
                    />
                </div>
            </If>
            <DetailTable
                {...props}
                pageInfo={state.pageInfo}
                updateState={action.thisAct.updateState}
                search={action.thisAct.search}
            />
        </div>
    );

});

export default DetailWarper;